package consume.listener;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

/**
 * @author Kevin
 * @date 2023/6/11 12:46
 * @description 监听简单模式消息
 **/
@Slf4j
@Component
public class SimpleListener {

  @RabbitListener(queuesToDeclare=@Queue("simple-queue"))
  public void listener(String msg, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag,
                       Channel channel) throws Exception{
    log.info("监听到简单消息--{}",msg);
    // 手动签收
    channel.basicAck(deliveryTag, true);

  }

}
